package com.skyline.spot.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import com.skyline.base.type.Activity;
import com.skyline.base.type.SpotRefrenceType;
import com.skyline.spot.model.SpotRefrence;

public class SpotRefrenceMapper implements RowMapper<SpotRefrence> {

	private final static SpotRefrenceMapper MAPPER = new SpotRefrenceMapper();

	private static final String COLUMN_ID = "id";
	private static final String COLUMN_SPOTID = "spotId";
	private static final String COLUMN_SPOTNAME = "spotName";
	private static final String COLUMN_SPOTPORTRAIT = "spotPortrait";

	private static final String COLUMN_REFRENCEID = "refrenceId";
	private static final String COLUMN_REFRENCEPORTRAIT = "refrencePortrait";
	private static final String COLUMN_REFRENCETITLE = "refrenceTitle";
	private static final String COLUMN_REFRENCEDIGEST = "refrenceDigest";
	private static final String COLUMN_REFRENCETYPE = "refrenceType";

	private static final String COLUMN_REFRENCEPROVIDERID = "ProviderId";
	private static final String COLUMN_REFRENCEPROVIDERNICKNAME = "ProviderNikename";
	private static final String COLUMN_REFRENCEPROVIDEREMAIL = "ProviderEmail";
	private static final String COLUMN_REFRENCEPROVIDERPORTRAIT = "ProviderPortrait";

	private static final String COLUMN_CREATETIME = "createTime";
	private static final String COLUMN_UPDATETIME = "updateTime";
	private final static String COLUMN_ACTIVITY = "activity";

	public static SpotRefrenceMapper getMapper() {
		return MAPPER;
	}

	public SpotRefrence mapRow(ResultSet rs, int rowNum) throws SQLException {
		SpotRefrence sr = new SpotRefrence();
		try {
			sr.setId(rs.getLong(COLUMN_ID));
			sr.setSpotId(rs.getLong(COLUMN_SPOTID));
			sr.setSpotName(rs.getString(COLUMN_SPOTNAME));
			sr.setSpotPortrait(rs.getString(COLUMN_SPOTPORTRAIT));
		} catch (Exception e) {

		}
		try {
			sr.setRefrenceId(rs.getLong(COLUMN_REFRENCEID));
			sr.setRefrenceportrait(rs.getString(COLUMN_REFRENCEPORTRAIT));
			sr.setRefrenceTitle(rs.getString(COLUMN_REFRENCETITLE));
			sr.setRefrenceDigest(rs.getString(COLUMN_REFRENCEDIGEST));
			sr.setRefrenceType(SpotRefrenceType.valueOf(rs
					.getString(COLUMN_REFRENCETYPE)));
		} catch (Exception e) {

		}
		try {
			sr.setProviderId(rs.getLong(COLUMN_REFRENCEPROVIDERID));
			sr.setProviderNikename(rs
					.getString(COLUMN_REFRENCEPROVIDERNICKNAME));
			sr.setProviderPortrait(rs
					.getString(COLUMN_REFRENCEPROVIDERPORTRAIT));
			sr.setProviderEmail(rs
					.getString(COLUMN_REFRENCEPROVIDEREMAIL));
		} catch (Exception e) {

		}
		
		try{
		sr.setCreateTime(rs.getDate(COLUMN_CREATETIME));
		sr.setUpdateTime(rs.getDate(COLUMN_UPDATETIME));
		sr.setActivity(Activity.valueOf((rs.getString(COLUMN_ACTIVITY))));
		}catch(Exception e){
			
		}
		return sr;
	}
}
